<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="com.jspsmart.upload.SmartUpload"%>
<%@page import="com.jspsmart.upload.File"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Insert title here</title>
</head>
<body>
	<%
		SmartUpload su = new SmartUpload();
		//初始化
		su.initialize(pageContext); //内置对象pageContext作为参数
		String allowed = "jpg,bmp,txt";
		su.setAllowedFilesList(allowed); //设置允许上传的扩展名
		String unallowed = "bat";
		su.setDeniedFilesList(unallowed); //不允许上传

		su.setMaxFileSize(1024 * 1024 * 2); //最大上传2M
		try {
			su.upload(); //上传到内存

			for (int i = 0; i < su.getFiles().getCount(); i++) { //多个上传
				File file = su.getFiles().getFile(i); //取得单个文件上传信息
				if (file.isMissing()) //判断是否为空上传项
					continue;

				String desc = su.getRequest().getParameter("desc"); //在upload()方法之后才可使用，获取表单信息
				out.print("上传描述:" + desc);
				file = su.getFiles().getFile(i); //取得单个文件上传信息
				String filePath = "file/";
				filePath += file.getFileName(); //设置文件在服务器保存位置
				file.saveAs(filePath, SmartUpload.SAVE_VIRTUAL); //文件另存到tomcat部署的项目文件夹中，不是当前项目物理位置
				//如果保存绝对路径，
				//file.saveAs(filePath,SmartUpload.SAVE_PHYSICAL);
				out.print(filePath);

			}
		} catch (Exception e) {
			out.write(e.toString());
			e.printStackTrace();
		}
	%>
</body>
</html>